package com.maomao.register;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.maomao.db.*;

public class ProcessMailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String registerID = request.getParameter("registerId");
		if(registerID == null){
			request.getRequestDispatcher("/err.jsp").forward(request,response);
			return ;
		}
		
		String studentId = (String)request.getSession().getAttribute(registerID);
		System.out.println(studentId);
		if(studentId == null || studentId.equals("")){
			request.getRequestDispatcher("/err.jsp").forward(request,response);
			return ;
		}
		
		String sql = "update person set isChecked = 1";
		
		DbConnection db = new DbConnection();
		
	
		try {
			db.update(sql);
			db.close();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
								
		request.setAttribute("registerName", studentId);
		
		
		request.getRequestDispatcher("/login.jsp").forward(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}